package com.sumainfor.wx.tenant.controller.alipay;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.qiniu.util.Json;
import com.sumainfor.common.Constants;
import com.sumainfor.common.alipayutils.AlipayUtil;
import com.sumainfor.common.alipayutils.MerUtil.Merchant;
import com.sumainfor.common.alipayutils.SignUtils;
import com.sumainfor.common.alipayutils.ZhiFuBaoUtil.ZhiFuMessage;
import com.sumainfor.common.config.RedisUtils;
import com.sumainfor.common.entity.TemplateData;
import com.sumainfor.common.util.*;
import com.sumainfor.common.utlis.ComUtils;
import com.sumainfor.common.utlis.CompuUtils;
import com.sumainfor.common.utlis.Jsapi_ticketUtil;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.common.wechat.WeChatConfig;
import com.sumainfor.wx.tenant.controller.MaintenanceApplicationController;
import com.sumainfor.wx.tenant.dao.TctenTenantCouponsMapper;
import com.sumainfor.wx.tenant.dao.UtilsMapper;
import com.sumainfor.wx.tenant.feign.EpcFeignClient;
import com.sumainfor.wx.tenant.feign.Zfeign.ZpcGmioFeign;
import com.sumainfor.wx.tenant.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.wx.tenant.feign.ZuulFeignClient;
import com.sumainfor.wx.tenant.service.WechatService;
import com.sumainfor.wx.tenant.service.impl.GmioFeign.TenantCouService;
import com.sun.javafx.collections.MappingChange;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.MapUtils;
import org.apache.http.message.BasicNameValuePair;
import org.apache.ibatis.annotations.Param;
import org.apache.xmlbeans.impl.jam.internal.parser.ParamStructPool;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Null;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author Meng
 * @ClassName AliPayController
 * @date 2019/12/6 18:29
 * @description: TODO
 */

@Log4j2
@Controller
@RequestMapping("/AliPayController")
public class AliPayController {

    @Autowired
    ZuulFeignClient zuulFeignClient;

    @Autowired
    WechatService wechatService;

    @Autowired
    ZpcMktFeign zpcMktFeign;

    @Autowired
    UtilsMapper utilsMapper;

    @Autowired
    ZpcGmioFeign zpcGmioFeign;

    @Autowired
    TctenTenantCouponsMapper tctenTenantCouponsMapper;

    @Autowired
    TenantCouService tenantCouService;
    @Autowired
    RedisUtils redisUtils;

    @Autowired
    EpcFeignClient epcFeignClient;



    public static final String NOTIFYURL ="http://47.96.150.97:7000/wechat/tenant/AliPayController/WeXinPayCompleted";//第一次支付房租
    public static final String NOTIFYURLYL = "http://47.96.150.97:7000/wechat/tenant/AliPayController/YinLianPayCompleted";//第一次支付水电燃宽和押金
    public static final String NOTIFYURLXZ = "http://47.96.150.97:7000/wechat/tenant/AliPayController/reletPaIdPayCompleted";//续租账单支付



    /**
     * 微信支付
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/WeXinPay")
    public JsonResult WeXinPay(@RequestBody Map<String, Object> params) {
        //参数
        // TenId,组可id
        // HouId,房源id
        // transAmt,金额
        //commodityName,商品名称
        //commodityDesc,商品描述
        //CouId//优惠券编号
        //PaId//hey
        //支付类型 prepayType(1微信 2支付宝)
        //authCode(支付宝的authCode)(不要)
        JsonResult result = new JsonResult();
        String Attestation ="";//返回给前端的


        params.put("FirstMon", 1);//首月
        params.put("DepositType", 1);//1房屋房租押金
        params.put("BiType", 1);//房租
        params.put("delfg", 0);//房租
        //获取首月房租账单
        JsonResult GmioResult = zpcGmioFeign.getFirstRoomGEW(params);
        Map<String, Object> getFirstRoomGEWMap = (Map<String, Object>) GmioResult.get("result");

        //获取当前时间
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String orderDate = sdf.format(nowTime);//租赁顾问签约抄水电燃,抄表记录的时间默认一致,

        Map<String, Object> payMap = new HashMap<>();
        payMap.put("transAmt", (long) CompuUtils.mul(MapUtils.getDouble(params, "transAmt"), new Double("100")));//交易金额(分)
        payMap.put("commodityName", params.get("commodityName"));//商品名称
        payMap.put("commodityDesc", params.get("commodityDesc"));//商品描述
        payMap.put("orderDate", orderDate);//商品描述
        payMap.put("orderNo", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));//商户订单号

        //获取组可签约房子的房源编号
        JsonResult getHouCorIdResult = zpcMktFeign.getHouCorId(params);
        Map<String, Object> getHouCorId = (Map<String, Object>) getHouCorIdResult.get("result");
        getHouCorId.put("area_id", getHouCorId.get("CorId"));

        JsonResult getAreaidResult = zuulFeignClient.getAreaid(getHouCorId);
        Map<String, Object> getAreaid = (Map<String, Object>) getAreaidResult.get("result");

        if(MapUtils.getInteger(params,"prepayType")==1) {//表示微信支付
            //获取openid
            Map<String, Object> tenOpIdMAP = wechatService.getTenOpenId(params);
            payMap.put("openid", tenOpIdMAP.get("uopid"));//微信用户id
            if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
                //上海唐巢投资公司不用.合并到公租房
                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
            } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
            } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
                payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.KS_WXSMGRN);//微信子商户号
                payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
            }
            payMap.put("notifyUrl", NOTIFYURL);//微信支付异步通知地址
            Attestation = AlipayUtil.AliPayPublic(payMap);
        }else if(MapUtils.getInteger(params,"prepayType")==2){//支付宝支付
            if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
                //上海唐巢投资公司不用.合并到公租房
                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                payMap.put("storeId", "tangchao001");//终端商户号名称
                payMap.put("terminalId", "tangchao001");//终端商户号名称
            } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                payMap.put("storeId", "tangchaoGZ001");//终端商户号名称
                payMap.put("terminalId", "tangchaoGZ001");//终端商户号名称
            } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
                payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.KS_ZFSMGRN);//支付宝子商户号
                payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
                payMap.put("storeId", "kunshan001");//终端商户号名称
                payMap.put("terminalId", "kunshan001");//终端商户号名称
            }
            payMap.put("notifyUrl", NOTIFYURL);//微信支付异步通知地址
            Attestation = AlipayUtil.ZhiFuBaopublic(payMap);
        }

        Map<String, Object> weChatMap = new HashMap<>();
        weChatMap.put("prepayId", payMap.get("orderNo"));
        weChatMap.put("prepayType",params.get("prepayType"));//本次支付方式1微信2支付宝 3银联支付
        weChatMap.put("Source", getFirstRoomGEWMap.get("BiId"));
        weChatMap.put("SouType", 1);
        weChatMap.put("Coucode", params.get("CouId"));
        weChatMap.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
        weChatMap.put("fnc",
                this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
        ParamsCommon.commonInsertParms(weChatMap);
        zpcGmioFeign.AddPayWechat(weChatMap);//保存本次订单号与账单编号之间的关系
        return result.put(Attestation);

    }

    /**
     * 判断支付宝扫码是否支付
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/IsPayStatus")
    public JsonResult IsPayStatus(@RequestBody Map<String,Object> params){
        return zpcGmioFeign.getFirstRoomGEW(params);
    }







    /**
     * 支付完成
     * PathVariable
     *
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/WeXinPayCompleted")
    public String WeXinPayCompleted (@RequestParam Map<String, Object> params) throws UnsupportedEncodingException{
        System.out.println(params);

        JsonResult result = new JsonResult();

        //获取当前时间
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String GenerateTimeNow = sdf.format(nowTime);//租赁顾问签约抄水电燃,抄表记录的时间默认一致,


//
//        StringBuffer ceshi = new StringBuffer();
//        ceshi.append("respCode=").append(params.get("respCode").toString()).append("&");
//        ceshi.append("orderNo=").append(params.get("orderNo").toString()).append("&");
//        ceshi.append("transId=").append(params.get("transId").toString()).append("&");
//        ceshi.append("orderDate=").append(params.get("orderDate").toString()).append("&");
//       // ceshi.append("bankType=").append(params.get("bankType").toString()).append("&");
//        ceshi.append("respDesc=").append(params.get("respDesc").toString()).append("&");
//        ceshi.append("transAmt=").append(params.get("transAmt").toString()).append("&");
//        ceshi.append("signature=").append(params.get("signature").toString()).append("&");
//        ceshi.append("merNo=").append(params.get("merNo").toString()).append("&");
//        ceshi.append("productId=").append(params.get("productId").toString());

//        String signStr = URLDecoder.decode(ceshi.toString(), "UTF-8");	//解码
//        TreeMap<String, String> tempMap = new TreeMap<String, String>();
//        String data[] = signStr.split("&");
//        Arrays.sort(data, String.CASE_INSENSITIVE_ORDER);
//        for(int i = 0; i < data.length; i ++){
//            String str = data[i];
//            String key = str.substring(0, str.indexOf("="));
//            String value = str.substring(str.indexOf("=")+1, str.length());
//            tempMap.put(key, value);
//        }
//
//        StringBuffer buf = new StringBuffer();
//        for (String key : tempMap.keySet()) {
//            buf.append(key).append("=").append((String) tempMap.get(key)).append("&");
//        }
//        String signatureStr = buf.substring(0, buf.length() - 1);
//        boolean signFlag = SignUtils.verferSignData(ceshi.toString());
//        if (!signFlag) {
//             System.out.println("验签失败");
//            return result.putFailed("验签失败");
//
//        } else {
        if (params.get("respCode").toString().equals("0000")) {//是支付成功的操作

            System.out.println("支付成功走修改账单的接口"+params);
            //修改账单状态,增加支付信息。orderNo//订单编号
            params.put("prepayId", params.get("orderNo"));//本次支付订单号
            JsonResult getBillPayResult = zpcGmioFeign.getBillPay(params);
            List<Map<String, Object>> getBillPayMapList = (List<Map<String, Object>>) getBillPayResult.get("result");//根据订单信息查询关联账单

            // Map<String, Object> getBillPayMap = new HashMap<>();
            for (Map<String, Object> getBillPayMap : getBillPayMapList) {//1对1的关系

                params.put("BiId", getBillPayMap.get("Source"));//订单关联的账单编号
                JsonResult getFirsMonRentResult = zpcGmioFeign.getFirstRoomGEW(params);//根据账单编号获取账单信息
                Map<String, Object> getFirstRoomGEWMap = (Map<String, Object>) getFirsMonRentResult.get("result");





                //增加本次支付信息
                String PayIdUUID = "";//支付订单号
                //获取账单编号
                Map<String, Object> payIduuid = utilsMapper.getUUID(new HashMap<String, Object>() {{
                    put("uuid", "PayId");
                    put("database", Constants.DATA_SOURCE_GMIO);
                    put("surface", "tcgmio_bill_pay");
                }});
                if (payIduuid != null) {
                    int number = Integer.valueOf(payIduuid.get("uuid").toString());
                    PayIdUUID = ComUtils.getLocalTrmSeqNum("ZF", number);

                } else {
                    PayIdUUID = ComUtils.getLocalTrmSeqNum("ZF", 0);
                }

                Map<String, Object> AddPayWechat = new HashMap<String, Object>();

                AddPayWechat.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                AddPayWechat.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonInsertParms(AddPayWechat);

                AddPayWechat.put("PayId", PayIdUUID);//支付信息编号
                AddPayWechat.put("TenId", getFirstRoomGEWMap.get("TenId"));//用户编号
                AddPayWechat.put("Shape", "0");//支付形式   0.线上   1.线下
                if (MapUtils.getInteger(getBillPayMap,"prepayType")==1) {
                    AddPayWechat.put("PayMode", "1");//支付方式  1.微信  2.支付宝,3银联支付
                }else if(MapUtils.getInteger(getBillPayMap,"prepayType")==2){
                    AddPayWechat.put("PayMode", "2");//支付方式  1.微信  2.支付宝,3银联支付
                }
                AddPayWechat.put("TransactionId", params.get("orderNo"));//微信支付订单号	该字段只有线上微信支付才有
                AddPayWechat.put("PayTime", GenerateTimeNow);//支付时间
                AddPayWechat.put("BiMoney", getFirstRoomGEWMap.get("BiMoney"));//本次账单金额
                AddPayWechat.put("PatStats", "2");//支付状态    1.未支付  2.支付成功
                AddPayWechat.put("PayMoney", getFirstRoomGEWMap.get("BiMoney"));//支付金额
                if (FieldCheckUtil.isMapFieldNotNull(getBillPayMap, new String[]{"Coucode"})) {
                    Map<String, Object> getTenantCouCount = tctenTenantCouponsMapper.getTenantCouCount(new HashMap<String, Object>() {{
                        put("CouId", getBillPayMap.get("Coucode"));
                        put("TenId", getFirstRoomGEWMap.get("TenId"));
                    }});

                    //优惠券大于0
                    if (MapUtils.isNotEmpty(getTenantCouCount)) {
                        Map<String, Object> cou = new HashMap<String, Object>();
                        cou.put("CouId", getBillPayMap.get("Coucode"));
                        cou.put("TenId", getFirstRoomGEWMap.get("TenId"));
                        //修改优惠券已使用
                        tenantCouService.UpdateTenantCou(cou);
                        AddPayWechat.put("Couponcd", getBillPayMap.get("Coucode"));//优惠券编号
                        AddPayWechat.put("Couponamt", getTenantCouCount.get("Facevalue"));//优惠券金额
                        AddPayWechat.put("PayMoney", CompuUtils.reduce(MapUtils.getDouble(getFirstRoomGEWMap, "BiMoney"), MapUtils.getDouble(getTenantCouCount, "Facevalue")));//优惠券金额

                    }

                }



                if (MapUtils.getInteger(getFirstRoomGEWMap,"Status")!=2){

                    //修改当前房租账单为支付成功
                    Map<String, Object> map2 = new HashMap<>();
                    map2.put("term","1");//1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
                    map2.put("fnc",
                            this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                    ParamsCommon.commonUpdateParms(map2);
                    map2.put("PayId", PayIdUUID);//支付信息编号
                    map2.put("Status", 2);//账单状态   1.待支付  2.支付完成
                    map2.put("Abnormal", 0);//账单异常状态   0正常   1异常
                    map2.put("BiId", getFirstRoomGEWMap.get("BiId"));
                    zpcGmioFeign.UpdateBill(map2);

                    if(MapUtils.getInteger(getFirstRoomGEWMap,"BiType")==1&&MapUtils.getInteger(getFirstRoomGEWMap,"FirstMon")==0){//不是首月房租账单





                        params.put("PaId",getFirstRoomGEWMap.get("Source"));
                        String StartTime = MapUtils.getString(getFirstRoomGEWMap,"BiGenerated");//首月房租开始时间
                        String EndTime = MapUtils.getString(getFirstRoomGEWMap,"EndTime");//首月房租结束时间
                        params.put("StartTime",StartTime);//钥匙开始时间
                        params.put("EndTime",EndTime);//钥匙结束时间
                        //获取在租租客的手机号
                        Map<String,Object> PhoneMap = tenantCouService.getTenPhone(getFirstRoomGEWMap);//获取在租租客的手机号
                        params.put("phone",PhoneMap.get("TenPhone"));//获取租客手机号
                        params.put("openid",PhoneMap.get("uopid"));//租客openid
                        List<Map<String,Object>> identifierList = new ArrayList<>();

                        //根据合同编号,去合同表查询智能门锁的情况
                        JsonResult resultRoom = zpcMktFeign.getIntelligentRoom(params);
                        Map<String,Object> IntellMap = (Map<String,Object>)resultRoom.get("result");

                        Integer IntelligentOpenType = new Integer("0");
                        Integer typeZhineng = new Integer("0");

                        if (IntellMap !=null){

                            IntelligentOpenType = MapUtils.getInteger(IntellMap,"IntelligentOpenType");//开门类型
                            typeZhineng =  MapUtils.getInteger(IntellMap,"IntelligentType");//开门类型
                            if (MapUtils.getString(IntellMap,"IntelligentRoom")!=null&&!MapUtils.getString(IntellMap,"IntelligentRoom").equals("")){
                                String IntelligentRoom = MapUtils.getString(IntellMap,"IntelligentRoom");
                                String IntelligentRooms = IntelligentRoom.substring(0,IntelligentRoom.length()-1);
                                String[] arr1 = IntelligentRooms.split(",");
                                for(String arrStr:arr1){
                                    Map<String,Object> identMap = new HashMap<>();
                                    identMap.put("Intelligent",IntellMap.get("IntelligentType"));//锁类型
                                    identMap.put("Identifier",arrStr.substring(0,arrStr.indexOf(":")));//锁编号
                                    identMap.put("CodeId",arrStr.substring(arrStr.indexOf(":")+1));//钥匙
                                    identifierList.add(identMap);
                                }
                            }
                        }







                        if(identifierList.size()>0){//有智能设备
                            //组装维修推送参数
                            Map<String,Object> weiMap=new HashMap<String,Object>();
                            weiMap.put("keyword1",new TemplateData(IntellMap.get("Province").toString()+
                                    IntellMap.get("City").toString()+
                                    IntellMap.get("District").toString()+
                                    IntellMap.get("Street").toString()+
                                    IntellMap.get("Address").toString()+
                                    IntellMap.get("Road").toString()+"路"+
                                    IntellMap.get("BuilDing").toString()+"楼"+
                                    IntellMap.get("Room").toString()+"室"
                                    ,"#4876FF"));//房源地址
                            weiMap.put("first", new TemplateData("欢迎入住唐巢公寓，您的开门密码如下" +
                                    "在门锁按键输入'密码+#'后便可开门", "#4876FF"));




                            //修改智能门锁周期
                            for (Map<String,Object> InteMap:identifierList){
                                //Intelligent 0.蜂电   1.大华   2.科技侠   3.果加
                                if (InteMap.get("Intelligent").toString().equals("2")){
                                    String DeviceLockToken=redisUtils.get("DeviceLockToken");
                                    //如果获取不到就重新登录
                                    if (DeviceLockToken==null){
                                        Map<String,Object> tokenMap=new HashMap<String, Object>();
                                        params.put("client_id", InteDeviceLockConfig.CLIENT_ID);
                                        params.put("client_secret",InteDeviceLockConfig.CLIENT_SECRET);
                                        params.put("grant_type",InteDeviceLockConfig.GRANT_TYPE_PASSWORD);
                                        params.put("username",InteDeviceLockConfig.USERNAME);
                                        params.put("password",InteDeviceLockConfig.PASSWORD);
                                        params.put("redirect_uri",InteDeviceLockConfig.REDIRECT_URL);
                                        tokenMap= InteDeviceLockUtil.oauth2Token(params);
                                        if (tokenMap.get("access_token")!=null){
                                            DeviceLockToken=tokenMap.get("access_token").toString();
                                            //token存到redis中
                                            redisUtils.set("DeviceLockToken",DeviceLockToken,Long.valueOf(tokenMap.get("expires_in").toString()));
                                        }else{
                                            result.putFailed("token获取失败");
                                        }
                                    }


                                    Map<String,Object> sendMap = new HashMap<>();
                                    sendMap.put("clientId", InteDeviceLockConfig.CLIENT_ID);//应用编号
                                    sendMap.put("accessToken",DeviceLockToken);//访问令牌
                                   // sendMap.put("keyId",InteMap.get("CodeId"));//智能设备编号
                                    sendMap.put("startDate",InteDeviceLockUtil.getTimeSign());//当前时间
                                    //  sendMap.put("startDate",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("StartTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_START,"yyyy-MM-dd HH:mm:ss"));
                                    sendMap.put("endDate",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                                    sendMap.put("date",InteDeviceLockUtil.getTimeSign());//当前时间(毫秒数)



                                    if(IntelligentOpenType==0){//表示蓝牙

                                        sendMap.put("keyId",InteMap.get("CodeId"));//智能设备编号
                                        Map<String,Object> mapResult=InteDeviceLockUtil.keyChangePeriod(sendMap);//修改科技侠有效期
                                        System.out.println("钥匙返回的参数:"+mapResult);
                                        System.out.println("InteMap1:"+InteMap);
                                        if (mapResult.get("errcode")!=null && mapResult.get("errcode").toString().equals("0")){
                                            result.putSuccess("修改科技侠智能门锁成功");

                                        }else{
                                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                            result.putFailed(mapResult.get("errmsg").toString());
                                        }


                                    }else if(IntelligentOpenType==1){//表示门锁
                                        sendMap.put("keyboardPwdId",InteMap.get("CodeId"));//密码id
                                        sendMap.put("lockId",InteMap.get("Identifier"));//锁
                                        Map<String,Object> mapResult=InteDeviceLockUtil.keyboardPwdChange(sendMap);//修改科技侠有效期
                                        System.out.println("钥匙返回的参数:"+mapResult);
                                        System.out.println("InteMap1:"+InteMap);
                                        if (mapResult.get("errcode")!=null && mapResult.get("errcode").toString().equals("0")){
                                            result.putSuccess("修改科技侠智能门锁成功");

                                        }else{
                                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                            result.putFailed(mapResult.get("errmsg").toString());
                                        }

                                    }




                                }else if(InteMap.get("Intelligent").toString().equals("3")){//果加
                                    String GuoJiaToken=redisUtils.get("GuoJiaToken");
                                    //如果获取不到就重新登录
                                    if (GuoJiaToken==null){
                                        Map<String,Object> guoJiaMap=new HashMap<String, Object>();
                                        guoJiaMap.put("s_id", InteGuoJiaUtil.getSid());
                                        guoJiaMap.put("version","1");
                                        com.alibaba.fastjson.JSONObject bodyJson=new com.alibaba.fastjson.JSONObject();
                                        //key
                                        DESEncrypt desPlus2 = new DESEncrypt(InteGuoJiaConfig.DES_KEY);
                                        //密码
                                        bodyJson.put("account",InteGuoJiaConfig.ACCOUNT);
                                        bodyJson.put("password",desPlus2.encrypt(InteGuoJiaConfig.PASSWORD));
                                        guoJiaMap= InteGuoJiaUtil.login(guoJiaMap,bodyJson);
                                        //返回的token数据
                                        Map<String,Object>dataMap=(Map<String,Object>)guoJiaMap.get("data");
                                        if (guoJiaMap.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                            GuoJiaToken=dataMap.get("access_token").toString();
                                            //token存到redis中
                                            redisUtils.set("GuoJiaToken",GuoJiaToken,Long.valueOf(dataMap.get("expires_second").toString()));
                                        }else{
                                            result.putFailed("token获取失败");
                                        }
                                    }
                                    //先解除果加的门锁授权在重新授权
                                    Map<String,Object> headParams=new HashMap<String, Object>();
                                    headParams.put("s_id",InteGuoJiaUtil.getSid());
                                    headParams.put("version","1");
                                    headParams.put("access_token",GuoJiaToken);


                                    if(IntelligentOpenType==0){//表示蓝牙

                                        JSONObject bodyJsonOne=new JSONObject();
                                        bodyJsonOne.put("lock_no",InteMap.get("Identifier"));//门锁编码
                                        bodyJsonOne.put("mobile",params.get("phone"));
                                        Map<String,Object> JieChuMap = InteGuoJiaUtil.lockCancel_auth(headParams,bodyJsonOne);
                                        if (JieChuMap.get("rlt_code") !=null && JieChuMap.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                            //解除成功再去授权
                                            JSONObject bodyJson=new JSONObject();
                                            bodyJson.put("operate_pwd_auth","N");//是否允许操作密码 Y 允许 N 不允许
                                            bodyJson.put("set_custom_pwd","N");//是否允许设置自定义密码 Y 允许 N 不允许智能是否允许设置自定义密码 Y 允许 N 不允许
                                            bodyJson.put("lock_no",InteMap.get("Identifier"));//智能门锁的设备编号
                                            bodyJson.put("mobile",params.get("phone"));//用户手机号
                                            bodyJson.put("auth_time_start",InteDeviceLockUtil.getTimeSign());
                                            // bodyJson.put("auth_time_start",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("StartTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_START,"yyyy-MM-dd HH:mm:ss"));
                                            bodyJson.put("auth_time_end",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                                            Map<String,Object> guoJiaResult=InteGuoJiaUtil.lockAuth(headParams,bodyJson);
                                            if (guoJiaResult.get("rlt_code") !=null && guoJiaResult.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                                InteMap.put("CodeId",InteMap.get("Identifier"));//钥匙的编码就存智能设备编码
                                                //InteMap.put("Code",InteMap.get("TenMode"));//果加的密码就存租客手机号
                                            }else{
                                                result.putFailed(guoJiaResult.get("rlt_msg").toString());
                                            }

                                        }else{
                                            result.putFailed(JieChuMap.get("rlt_msg").toString());
                                        }

                                    }else if (IntelligentOpenType==1){//表示密码

                                        //继续新增离线时效性密码
                                        JSONObject bodyJsonOne=new JSONObject();
                                        bodyJsonOne.put("lock_no",InteMap.get("Identifier"));//门锁编码
                                        Date dayss = new Date();
                                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                                        bodyJsonOne.put("valid_time_start",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(df.format(dayss),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_START,"yyyy-MM-dd HH:mm:ss"));//开始时间
                                        bodyJsonOne.put("valid_time_end",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                                        bodyJsonOne.put("pwd_user_mobile",params.get("phone"));//手机号
                                        Map<String,Object> guoJiaResult=InteGuoJiaUtil.pwd_offlineadd(headParams,bodyJsonOne);
                                        DESEncrypt desPlus2 = new DESEncrypt(InteGuoJiaConfig.DES_KEY);
                                        String d2="";
                                        String pwd_no="";
                                        try {
                                            Map<String,Object> dataMap=(Map<String,Object>)guoJiaResult.get("data");
                                            d2 = desPlus2.decrypt(DESEncrypt.byteArr2HexStr(DESEncrypt.hexStringToBytes(dataMap.get("pwd_text").toString())));
                                            pwd_no = dataMap.get("pwd_no").toString();
                                        }catch (Exception e){
                                            log.debug("键盘密码解密错误"+e);
                                        }

                                        if (guoJiaResult.get("rlt_code").toString().equals("HH0000")){//HH0000 请求成功
                                            InteMap.put("CodeId",pwd_no);//钥匙id
                                            InteMap.put("keyboardPwd",d2);//钥匙内容

                                        }else{
                                             result.putFailed("服务器繁忙");
                                        }

                                    }

                                }
                            }


                            if(IntelligentOpenType==1 && typeZhineng==3){//表示密码开门并且类型是果加.发送推送给租客


                                JsonResult epcResult = epcFeignClient.getTenRoom(IntellMap);
                                List<Map<String,Object>> epcIdenList = (List<Map<String, Object>>) epcResult.get("result");


                                StringBuffer keyword3Buffer = new StringBuffer();
                                for (Map<String,Object> map6:identifierList) {//测试map,保存本次签约门锁的密码
                                    for (Map<String,Object> map5:epcIdenList) {

                                        if((MapUtils.getString(map6,"Identifier")!=null&&MapUtils.getString(map5,"Identifier")!=null&&MapUtils.getString(map6,"Identifier").equals(MapUtils.getString(map5,"Identifier")))){
                                            map6.putAll(map5);
                                        }
                                    }
                                }

                                for (Map<String,Object> map4:identifierList){//测试map,保存本次签约门锁的密码
                                    if (MapUtils.getInteger(map4,"HouConType")==1){
                                        weiMap.put("keyword2",new TemplateData(map4.get("keyboardPwd").toString(), "#4876FF"));
                                    }else if(MapUtils.getInteger(map4,"HouConType")==2){
                                        keyword3Buffer.append(MapUtils.getString(map4,"HouConName")).append(":");
                                        keyword3Buffer.append(MapUtils.getString(map4,"keyboardPwd")).append(";");
                                    }

                                }
                                weiMap.put("keyword3",new TemplateData(keyword3Buffer.toString(), "#4876FF"));
                                //发送短信推送
                                Jsapi_ticketUtil.sendTemplate(params.get("openid").toString(), WeChatConfig.SEND_KEY,"","#4876FF", net.sf.json.JSONObject.fromObject(weiMap));
                            }
                        }

                    }

                    //如果首月房租,修改合同表房租为支付完成
                    if(MapUtils.getInteger(getFirstRoomGEWMap,"BiType")==1&&MapUtils.getInteger(getFirstRoomGEWMap,"FirstMon")==1) {//首月房租账单
                        getFirstRoomGEWMap.put("RentStatus",2);//房租支付完成
                        getFirstRoomGEWMap.put("PaId",getFirstRoomGEWMap.get("Source"));//房租支付完成
                        getFirstRoomGEWMap.put("nimeide",1);
                        zpcMktFeign.upPaIdFlow(getFirstRoomGEWMap);

                    }



                }
                if (MapUtils.getString(getFirstRoomGEWMap,"PayId")==null||MapUtils.getString(getFirstRoomGEWMap,"PayId").equals("")){
                    zpcGmioFeign.AddBillPay(AddPayWechat);//增加支付信息
                }else{
                    JsonResult PayResult =  zpcGmioFeign.getBillPays(getFirstRoomGEWMap);
                    Map<String,Object> PayMap = (Map<String, Object>) PayResult.get("result");
                    if (MapUtils.getInteger(PayMap,"coutPay")==0){
                        zpcGmioFeign.AddBillPay(AddPayWechat);//增加支付信息
                    }
                }

            }

        }
        return "SUCCESS";
    }
    //   }

    /**
     * 银联支付
     *
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/YinLianPay")
    public JsonResult YinLianPay(@RequestBody Map<String, Object> params) {

        //参数
        // TenId,组可id
        // HouId,房源id
        // transAmt,金额
        //commodityName,商品名称(第一次公共事业费加押金)
        //commodityDesc,商品描述(公共事业费)
        //CouId//优惠券编号
        //PaId//合同编号
        //多加一个参数
        //HouInfoId(房源详表编号)

        //prepayType(1微信 2表示支付寶)

        System.out.println("接受的参数"+params);
        JsonResult result = new JsonResult();
        String Attestation = "";

        String TenIds = MapUtils.getString(params, "TenId");

        //获取当前时间
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String orderDate = sdf.format(nowTime);//租赁顾问签约抄水电燃,抄表记录的时间默认一致,


//
//        payMap.put("transAmt", (long) CompuUtils.mul(MapUtils.getDouble(params, "transAmt"), new Double("100")));//交易金额(分)
//        payMap.put("commodityName", params.get("commodityName"));//商品名称
//        payMap.put("commodityDesc", params.get("commodityDesc"));//商品描述
//        payMap.put("orderDate", orderDate);//商品描述
//        payMap.put("orderNo", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));//商户订单号

        Map<String, Object> payMap = new HashMap<>();
        payMap.put("transAmt", (long) CompuUtils.mul(MapUtils.getDouble(params, "transAmt"), new Double("100")));//交易金额(分)
        payMap.put("commodityName", params.get("commodityName"));//商品名称
        payMap.put("commodityDesc", params.get("commodityDesc"));//商品描述
        payMap.put("orderDate", orderDate);//订单日期
        payMap.put("orderNo", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));//商户订单号
        //   payMap.put("frontUrl", "http://www.4006269069.net/");//前台通知地址


        //获取组可签约房子的房源编号
        JsonResult getHouCorIdResult = zpcMktFeign.getHouCorId(params);
        Map<String, Object> getHouCorId = (Map<String, Object>) getHouCorIdResult.get("result");
        getHouCorId.put("area_id", getHouCorId.get("CorId"));

        JsonResult getAreaidResult = zuulFeignClient.getAreaid(getHouCorId);
        Map<String, Object> getAreaid = (Map<String, Object>) getAreaidResult.get("result");


        if(MapUtils.getInteger(params,"prepayType")==1) {//表示微信支付
            //获取openid
            Map<String, Object> tenOpIdMAP = wechatService.getTenOpenId(params);
            payMap.put("openid", tenOpIdMAP.get("uopid"));//微信用户id

            payMap.put("merNo", Merchant.EWG_ORMERN);//机构商户号
            payMap.put("terMerNo", Merchant.EWG_TEMERN);//终端商户号
            payMap.put("subChnlMerNo", Merchant.EWG_WXSMGRN);//微信子商户号
            payMap.put("subMerName", Merchant.EWG_TEMGRMING);//终端商户号名称



//            if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
//                //上海唐巢投资公司不用.合并到公租房
//                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
//                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//            } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
//                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
//                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//            } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
//                payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
//                payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
//                payMap.put("subChnlMerNo", Merchant.KS_WXSMGRN);//微信子商户号
//                payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
//            }
            payMap.put("notifyUrl", NOTIFYURLYL);//微信支付异步通知地址
            Attestation = AlipayUtil.AliPayPublic(payMap);
        }else if(MapUtils.getInteger(params,"prepayType")==2){//支付宝支付

            payMap.put("merNo", Merchant.EWG_ORMERN);//机构商户号
            payMap.put("terMerNo", Merchant.EWG_TEMERN);//终端商户号
            payMap.put("subChnlMerNo", Merchant.EWG_ZFSMGRN);//支付宝子商户号
            payMap.put("subMerName", Merchant.EWG_TEMGRMING);//终端商户号名称
            payMap.put("storeId", "tangchao001");//终端商户号名称
            payMap.put("terminalId", "tangchao001");//终端商户号名称





//            if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
//                //上海唐巢投资公司不用.合并到公租房
//                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
//                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//                payMap.put("storeId", "tangchao001");//终端商户号名称
//                payMap.put("terminalId", "tangchao001");//终端商户号名称
//            } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
//                payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
//                payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//                payMap.put("storeId", "tangchaoGZ001");//终端商户号名称
//                payMap.put("terminalId", "tangchaoGZ001");//终端商户号名称
//            } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
//                payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
//                payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
//                payMap.put("subChnlMerNo", Merchant.KS_ZFSMGRN);//支付宝子商户号
//                payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
//                payMap.put("storeId", "kunshan001");//终端商户号名称
//                payMap.put("terminalId", "kunshan001");//终端商户号名称
//            }
            payMap.put("notifyUrl", NOTIFYURLYL);//支付宝支付异步通知地址
            Attestation = AlipayUtil.ZhiFuBaopublic(payMap);
        }
//        payMap.put("notifyUrl",NOTIFYURLYL);//前台通知地址
//
//        String Attestation = AlipayUtil.AliPayPrivate(payMap);



        Map<String, Object> YinLianMap = new HashMap<>();
        YinLianMap.put("prepayId", payMap.get("orderNo"));
        YinLianMap.put("prepayType",params.get("prepayType"));
        YinLianMap.put("SouType", 2);
        YinLianMap.put("Coucode", params.get("CouId"));
        YinLianMap.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
        YinLianMap.put("fnc",
                this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
        ParamsCommon.commonInsertParms(YinLianMap);

        Map<String, Object> GuDingMoney = new HashMap<>();
        GuDingMoney.put("Source", params.get("PaId"));//合同编号
        GuDingMoney.put("PaId", params.get("PaId"));//合同编号
        GuDingMoney.put("FirstMon", 1);//是否首月
        GuDingMoney.put("BiType", 2);//公共事业费
        GuDingMoney.put("Status", 1);//待支付
        //算是否有第一次固定水费  PubType = 1
        GuDingMoney.put("PubType", 1);//水费
        JsonResult WatResult = zpcGmioFeign.getFirstRoomGEW(GuDingMoney);
        Map<String, Object> WatMap = (Map<String, Object>) WatResult.get("result");
        if (WatMap != null) {//表示有第一次固定水费

            YinLianMap.put("Source", WatMap.get("BiId"));
            YinLianMap.put("prepayType",params.get("prepayType"));
            zpcGmioFeign.AddPayWechat(YinLianMap);//保存本次订单号与账单编号之间的关系
        }
        GuDingMoney.put("PubType", 3);//燃费
        JsonResult GasResult = zpcGmioFeign.getFirstRoomGEW(GuDingMoney);
        Map<String, Object> GasMap = (Map<String, Object>) GasResult.get("result");
        if (GasMap != null) {//表示有第一次固定燃气
            YinLianMap.put("Source", GasMap.get("BiId"));
            YinLianMap.put("prepayType",params.get("prepayType"));
            zpcGmioFeign.AddPayWechat(YinLianMap);//保存本次订单号与账单编号之间的关系
        }
        GuDingMoney.put("PubType", 4);//宽
        JsonResult KuanResult = zpcGmioFeign.getFirstRoomGEW(GuDingMoney);
        Map<String, Object> KuanMap = (Map<String, Object>) KuanResult.get("result");
        if (KuanMap != null) {//表示有第一次固定水费
            YinLianMap.put("Source", KuanMap.get("BiId"));
            YinLianMap.put("prepayType",params.get("prepayType"));
            zpcGmioFeign.AddPayWechat(YinLianMap);//保存本次订单号与账单编号之间的关系
        }

        Map<String,Object> yajinMap = new HashMap<>();
        yajinMap.put("BiType",1);
        yajinMap.put("DepositType",2);
        yajinMap.put("Status",1);
        yajinMap.put("Source",params.get("PaId"));
        yajinMap.put("PaId",params.get("PaId"));
        System.out.println("生成水电押金穿的参数"+yajinMap);
        JsonResult YaResult = zpcGmioFeign.getFirstRoomGEW(yajinMap);
        Map<String, Object> YaMap = (Map<String, Object>) YaResult.get("result");
        if (YaMap != null) {//表示第一次水电押金


            Integer Intelligent = new Integer("0");
            JsonResult MktResult = zpcMktFeign.getHouRoom(params);//根据合同编号.查询该合同下的智能设备
            List<Map<String,Object>> MktList = (List<Map<String, Object>>) MktResult.get("result");
            StringBuffer stringss = new StringBuffer();
            for (Map<String,Object> MktMap:MktList){
                if (MapUtils.getString(MktMap,"Identifier")!=null&&!MapUtils.getString(MktMap,"Identifier").equals("")) {
                    stringss.append(MapUtils.getString(MktMap, "Identifier")).append(",");
                    Intelligent =MapUtils.getInteger(MktMap,"Intelligent");
                }
            }

            YinLianMap.put("Source", YaMap.get("BiId"));
            YinLianMap.put("Intelligent",Intelligent);
            YinLianMap.put("Identifier",stringss.toString());
            YinLianMap.put("SourcePaId", params.get("PaId"));
            YinLianMap.put("TenId", params.get("TenId"));
            YinLianMap.put("prepayType",params.get("prepayType"));

            //YinLianMap.put("HouInfoId", params.get("HouInfoId"));
            zpcGmioFeign.AddPayWechat(YinLianMap);//保存本次订单号与账单编号之间的关系

        }




        return result.put(Attestation);

    }



    /**
     * 第一次
     *
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/YinLianPayCompleted")
    public JsonResult YinLianPayCompleted(@RequestParam Map<String, Object> params) {

        System.out.println("1111111111111111111111111111111111111111111"+params);
        JsonResult result = new JsonResult();

        //获取当前时间
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String GenerateTimeNow = sdf.format(nowTime);//租赁顾问签约抄水电燃,抄表记录的时间默认一致,

//        StringBuffer buf = new StringBuffer();
//        for (String key : params.keySet()) {
//            buf.append(key).append("=").append((String) params.get(key)).append("&");
//        }
//        String signatureStr = buf.substring(0, buf.length() - 1);
//        boolean signFlag = false;
//        try {
//            signFlag = SignUtils.verferSignDatas(signatureStr);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }
//        if (!signFlag) {
//            // System.out.println("验签失败");
//            return result.putFailed("验签失败");
//        } else {
        System.out.println("验签成功");
        if (params.get("respCode").toString().equals("0000")) {//是支付成功的操作
            //修改账单状态,增加支付信息。orderNo//订单编号
            params.put("prepayId", params.get("orderNo"));//本次支付订单号
            System.out.println("进入方法");
            System.out.println("进入方法的参数"+params);
            JsonResult getBillPayResult = zpcGmioFeign.getBillPay(params);
            List<Map<String, Object>> getBillPayMapList = (List<Map<String, Object>>) getBillPayResult.get("result");//根据订单信息查询关联账单
            for (Map<String, Object> getBillPayMap : getBillPayMapList) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("BiId", getBillPayMap.get("Source"));//账单编号
                JsonResult getFirsMonRentResult = zpcGmioFeign.getFirstRoomGEW(map1);//根据账单编号获取账单信息
                Map<String, Object> getFirstRoomGEWMap = (Map<String, Object>) getFirsMonRentResult.get("result");

                //增加本次支付信息
                String PayIdUUID = "";//支付订单号
                //获取账单编号
                Map<String, Object> payIduuid = utilsMapper.getUUID(new HashMap<String, Object>() {{
                    put("uuid", "PayId");
                    put("database", Constants.DATA_SOURCE_GMIO);
                    put("surface", "tcgmio_bill_pay");
                }});
                if (payIduuid != null) {
                    int number = Integer.valueOf(payIduuid.get("uuid").toString());
                    PayIdUUID = ComUtils.getLocalTrmSeqNum("ZF", number);

                } else {
                    PayIdUUID = ComUtils.getLocalTrmSeqNum("ZF", 0);
                }

                Map<String, Object> AddPayWechat = new HashMap<String, Object>();

                AddPayWechat.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                AddPayWechat.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonInsertParms(AddPayWechat);

                AddPayWechat.put("PayId", PayIdUUID);//支付信息编号
                AddPayWechat.put("TenId", getFirstRoomGEWMap.get("TenId"));//用户编号
                AddPayWechat.put("Shape", "0");//支付形式   0.线上   1.线下
                AddPayWechat.put("PayMode", getBillPayMap.get("prepayType"));//支付方式  1.微信  2.支付宝  3 银联支付
                AddPayWechat.put("TransactionId", params.get("orderNo"));//微信支付订单号	该字段只有线上微信支付才有
                AddPayWechat.put("PayTime", GenerateTimeNow);//支付时间
                AddPayWechat.put("BiMoney", getFirstRoomGEWMap.get("BiMoney"));//本次账单金额
                AddPayWechat.put("PatStats", "2");//支付状态    1.未支付  2.支付成功
                AddPayWechat.put("PayMoney", getFirstRoomGEWMap.get("BiMoney"));//支付金额
                if (FieldCheckUtil.isMapFieldNotNull(getBillPayMap, new String[]{"Coucode"})) {
                    Map<String, Object> getTenantCouCount = tctenTenantCouponsMapper.getTenantCouCount(new HashMap<String, Object>() {{
                        put("CouId", getBillPayMap.get("Coucode"));
                        put("TenId", getFirstRoomGEWMap.get("TenId"));
                    }});

                    //优惠券大于0
                    if (MapUtils.isNotEmpty(getTenantCouCount)) {
                        Map<String, Object> cou = new HashMap<String, Object>();
                        cou.put("CouId", getBillPayMap.get("Coucode"));
                        cou.put("TenId", getFirstRoomGEWMap.get("TenId"));
                        //修改优惠券已使用
                        tenantCouService.UpdateTenantCou(cou);
                        AddPayWechat.put("Couponcd", getBillPayMap.get("Coucode"));//优惠券编号
                        AddPayWechat.put("Couponamt", getTenantCouCount.get("Facevalue"));//优惠券金额
                        AddPayWechat.put("PayMoney", CompuUtils.reduce(MapUtils.getDouble(getFirstRoomGEWMap, "BiMoney"), MapUtils.getDouble(getTenantCouCount, "Facevalue")));//优惠券金额

                    }

                }

                //修改当前账单为支付成功
                Map<String, Object> map2 = new HashMap<>();
                map2.put("term","1");//1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
                map2.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonUpdateParms(map2);
                map2.put("PayId", PayIdUUID);//支付信息编号
                map2.put("Status", 2);//账单状态   1.待支付  2.支付完成
                map2.put("Abnormal", 0);//账单异常状态   0正常   1异常
                map2.put("BiId", getFirstRoomGEWMap.get("BiId"));



                if (MapUtils.getInteger(getFirstRoomGEWMap,"Status")!=2) {
                    zpcGmioFeign.UpdateBill(map2);
                }




                if (MapUtils.getString(getFirstRoomGEWMap,"PayId")==null||MapUtils.getString(getFirstRoomGEWMap,"PayId").equals("")){
                    zpcGmioFeign.AddBillPay(AddPayWechat);//增加支付信息
                }else{
                    JsonResult PayResult =  zpcGmioFeign.getBillPays(getFirstRoomGEWMap);
                    Map<String,Object> PayMap = (Map<String, Object>) PayResult.get("result");
                    if (MapUtils.getInteger(PayMap,"coutPay")==0){
                        zpcGmioFeign.AddBillPay(AddPayWechat);//增加支付信息
                    }
                }


                if ((MapUtils.getInteger(getFirstRoomGEWMap,"BiType")==2&&MapUtils.getInteger(getFirstRoomGEWMap,"FirstMon")==1)
                        ||(MapUtils.getInteger(getFirstRoomGEWMap,"BiType")==1&&MapUtils.getInteger(getFirstRoomGEWMap,"DepositType")==2)
                ){
                    //修改电子合同状态为已支付
                    getFirstRoomGEWMap.put("PaId",getFirstRoomGEWMap.get("Source"));
                    getFirstRoomGEWMap.put("nimeide",3);
                    System.out.println("1111111111111111111111111111");
                    System.out.println("修改合同水电支付状态");
                    JsonResult MktPaId = zpcMktFeign.getPatIfFlPaysss(getFirstRoomGEWMap);
                    Map<String,Object> MktPaIdMap = (Map<String, Object>) MktPaId.get("result");
                    if(MapUtils.getInteger(MktPaIdMap,"coutPaId")==0){
                        zpcMktFeign.upPaIdFlow(getFirstRoomGEWMap);
                    }

                    //根据合同编号获取第一次房租账单
                    Map<String,Object> FangZuMap = new HashMap<>();
                    FangZuMap.put("PaId",getBillPayMap.get("SourcePaId"));//来源合同编号
                    FangZuMap.put("BiType",1);//房租账单
                    FangZuMap.put("FirstMon",1);//房租账单是否首月
                    FangZuMap.put("DepositType",1);//房租类型
                    JsonResult FangZuResult = zpcGmioFeign.getFirstRoomGEW(FangZuMap);//获取该合同首月房租账单的周期.并以此周期作为智能门锁的周期发送钥匙
                    Map<String,Object> FangZuMaps = (Map<String, Object>) FangZuResult.get("result");
                    String StartTime = MapUtils.getString(FangZuMaps,"BiGenerated");//首月房租开始时间
                    String EndTime = MapUtils.getString(FangZuMaps,"EndTime");//首月房租结束时间
                    params.put("StartTime",StartTime);//钥匙开始时间
                    params.put("EndTime",EndTime);//钥匙结束时间


                    if(MapUtils.getInteger(getFirstRoomGEWMap,"DepositType")==2){//表示本次循环是水电押金

                        String sss = getBillPayMap.get("Identifier").toString();
                        if (sss!=null&&!sss.equals("")){//表示存在智能门锁
                            String ssss = sss.substring(0,sss.length()-1);
                            String[] arr1 = ssss.split(",");
                            Integer Intelligent = MapUtils.getInteger(getBillPayMap,"Intelligent");//智能门锁的类型
                            List<Map<String,Object>> identifierList = new ArrayList<>();
                            for (String arr1String:arr1){
                                Map<String,Object> Zhineng = new HashMap<>();
                                Zhineng.put("Intelligent",Intelligent);//智能门锁类型
                                Zhineng.put("Identifier",arr1String);
                                identifierList.add(Zhineng);
                            }

                            Map<String,Object> PhoneMap = tenantCouService.getTenPhone(getBillPayMap);//获取在租租客的手机号
                            params.put("phone",PhoneMap.get("TenPhone"));//获取租客手机号
                            //支付完水电押金发钥匙
                            for (Map<String,Object> InteMap:identifierList){
                                //Intelligent 0.蜂电   1.大华   2.科技侠   3.果加
                                if (InteMap.get("Intelligent").toString().equals("2")){
                                    String DeviceLockToken=redisUtils.get("DeviceLockToken");
                                    //如果获取不到就重新登录
                                    if (DeviceLockToken==null){
                                        Map<String,Object> tokenMap=new HashMap<String, Object>();
                                        params.put("client_id", InteDeviceLockConfig.CLIENT_ID);
                                        params.put("client_secret",InteDeviceLockConfig.CLIENT_SECRET);
                                        params.put("grant_type",InteDeviceLockConfig.GRANT_TYPE_PASSWORD);
                                        params.put("username",InteDeviceLockConfig.USERNAME);
                                        params.put("password",InteDeviceLockConfig.PASSWORD);
                                        params.put("redirect_uri",InteDeviceLockConfig.REDIRECT_URL);
                                        tokenMap= InteDeviceLockUtil.oauth2Token(params);
                                        if (tokenMap.get("access_token")!=null){
                                            DeviceLockToken=tokenMap.get("access_token").toString();
                                            //token存到redis中
                                            redisUtils.set("DeviceLockToken",DeviceLockToken,Long.valueOf(tokenMap.get("expires_in").toString()));
                                        }else{
                                            return result.putFailed("token获取失败");
                                        }
                                    }
                                    Map<String,Object> sendMap = new HashMap<>();
                                    sendMap.put("clientId", InteDeviceLockConfig.CLIENT_ID);//应用编号
                                    sendMap.put("accessToken",DeviceLockToken);//访问令牌
                                    sendMap.put("lockId",InteMap.get("Identifier"));//智能设备编号
                                    sendMap.put("receiverUsername",params.get("phone"));//接收方用户名
                                    sendMap.put("keyName","科技侠");//钥匙名
                                    sendMap.put("startDate",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("StartTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_START,"yyyy-MM-dd HH:mm:ss"));
                                    sendMap.put("endDate",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                                    sendMap.put("remarks","发送钥匙");//备注,留言
                                    sendMap.put("remoteEnable",2);//是否支持远程开锁 1是 2 否
                                    sendMap.put("date",InteDeviceLockUtil.getTimeSign());//当前时间(毫秒数)
                                    Map<String,Object> mapResult=InteDeviceLockUtil.keySend(sendMap);
                                    System.out.println("钥匙返回的参数:"+mapResult);
                                    System.out.println("InteMap1:"+InteMap);
                                    if (mapResult.get("errcode")!=null && mapResult.get("errcode").toString().equals("0")){
                                        InteMap.put("CodeId",mapResult.get("keyId"));//密码ID
                                        //     InteMap.put("Operator",ContextUtils.getUserId());
                                    }else{
                                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                        return  result.putFailed(mapResult.get("errmsg").toString());
                                    }

                                }else if(InteMap.get("Intelligent").toString().equals("3")){//果加
                                    String GuoJiaToken=redisUtils.get("GuoJiaToken");
                                    //如果获取不到就重新登录
                                    if (GuoJiaToken==null){
                                        Map<String,Object> guoJiaMap=new HashMap<String, Object>();
                                        guoJiaMap.put("s_id", InteGuoJiaUtil.getSid());
                                        guoJiaMap.put("version","1");
                                        com.alibaba.fastjson.JSONObject bodyJson=new com.alibaba.fastjson.JSONObject();
                                        //key
                                        DESEncrypt desPlus2 = new DESEncrypt(InteGuoJiaConfig.DES_KEY);
                                        //密码
                                        bodyJson.put("account",InteGuoJiaConfig.ACCOUNT);
                                        bodyJson.put("password",desPlus2.encrypt(InteGuoJiaConfig.PASSWORD));
                                        guoJiaMap= InteGuoJiaUtil.login(guoJiaMap,bodyJson);
                                        //返回的token数据
                                        Map<String,Object>dataMap=(Map<String,Object>)guoJiaMap.get("data");
                                        if (guoJiaMap.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                            GuoJiaToken=dataMap.get("access_token").toString();
                                            //token存到redis中
                                            redisUtils.set("GuoJiaToken",GuoJiaToken,Long.valueOf(dataMap.get("expires_second").toString()));
                                        }else{
                                            return result.putFailed("token获取失败");
                                        }
                                    }
                                    /*发送果加的门锁钥匙*/
                                    Map<String,Object> headParams=new HashMap<String, Object>();
                                    headParams.put("s_id",InteGuoJiaUtil.getSid());
                                    headParams.put("version","1");
                                    headParams.put("access_token",GuoJiaToken);
                                    JSONObject bodyJson=new JSONObject();
                                    bodyJson.put("operate_pwd_auth","Y");//是否允许操作密码 Y 允许 N 不允许
                                    bodyJson.put("set_custom_pwd","Y");//是否允许设置自定义密码 Y 允许 N 不允许智能是否允许设置自定义密码 Y 允许 N 不允许
                                    bodyJson.put("lock_no",InteMap.get("Identifier"));//智能门锁的设备编号
                                    bodyJson.put("mobile",params.get("phone"));//用户手机号
                                    bodyJson.put("auth_time_start",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("StartTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_START,"yyyy-MM-dd HH:mm:ss"));
                                    bodyJson.put("auth_time_end",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                                    Map<String,Object> guoJiaResult=InteGuoJiaUtil.lockAuth(headParams,bodyJson);
                                    if (guoJiaResult.get("rlt_code") !=null && guoJiaResult.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                        InteMap.put("CodeId",InteMap.get("Identifier"));//钥匙的编码就存智能设备编码
                                        //InteMap.put("Code",InteMap.get("TenMode"));//果加的密码就存租客手机号
                                    }else{
                                        return result.putFailed(guoJiaResult.get("rlt_msg").toString());
                                    }
                                }
                            }


                            StringBuffer IntelligentRoomBuffer = new StringBuffer();
                            Integer IntelligentType = new Integer("0");
                            for (Map<String,Object> map4:identifierList){//测试map,保存本次签约门锁的密码
                                if (MapUtils.getString(map4,"CodeId")!=null||!MapUtils.getString(map4,"CodeId").equals("")) {
                                    IntelligentRoomBuffer.append(MapUtils.getString(map4, "Identifier")).append(":").append(MapUtils.getString(map4, "CodeId")).append(",");
                                    IntelligentType = MapUtils.getInteger(map4,"Intelligent");//智能门锁类型 2科技侠 3果加
                                }
                            }
                            //修改合同表里面的智能门锁编号
                            Map<String,Object> PactUpMap = new HashMap<>();
                            PactUpMap.put("term","1");//1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
                            PactUpMap.put("fnc",
                                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                            ParamsCommon.commonUpdateParms(PactUpMap);
                            PactUpMap.put("IntelligentRoom",IntelligentRoomBuffer.toString());
                            PactUpMap.put("IntelligentType",IntelligentType);
                            PactUpMap.put("PaId",getBillPayMap.get("SourcePaId"));
                            PactUpMap.put("nimeide",1);
                            zpcMktFeign.upPaIdFlow(PactUpMap);//修改合同表的智能门锁编号
                        }
                    }

                }
            }

        }

        return result.putSuccess("支付成功");
        //   }

    }

    /**
     * 租客全部账单支付
     */
    @ResponseBody
    @PostMapping("/TenPaymoney")
    public JsonResult TenPaymoney( @RequestBody  Map<String, Object> params) {

        JsonResult result = new JsonResult();
        String Attestation = "";
        //传参数
        //BiId,
        // TenId,
        // BiMoney,==transAmt
        // CorId,
        // BiName
        // BiType = 1
        // DepositType = 1
        // Source//账单来源
        // BiGenerated//账单生成日
        //EndTime //账单结束日
        //支付类型 prepayType(1微信 2支付宝)





        params.put("area_id", params.get("CorId"));
        params.put("transAmt", params.get("BiMoney"));
        String TenIds = MapUtils.getString(params,"TenId");//租客编号
        //获取当前时间
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String orderDate = sdf.format(nowTime);//租赁顾问签约抄水电燃,抄表记录的时间默认一致,


        System.out.println("params"+params);
        if ((params.get("BiType").toString().equals("1") &&params.get("DepositType").toString().equals("1"))||
                params.get("BiType").toString().equals("3")||
                params.get("BiType").toString().equals("4")||
                params.get("BiType").toString().equals("5")||
                params.get("BiType").toString().equals("6")||
                params.get("BiType").toString().equals("7")||
                params.get("BiType").toString().equals("8")||
                params.get("BiType").toString().equals("9")||
                params.get("BiType").toString().equals("10")||
                params.get("BiType").toString().equals("11")
        ) {//表明除了公共事业费，所有的都走微信支付或者支付宝扫码支付

            Map<String, Object> payMap = new HashMap<>();
            payMap.put("transAmt", (long) CompuUtils.mul(new Double(params.get("transAmt").toString()), new Double("100")));//交易金额(分)
            payMap.put("commodityName", params.get("BiName"));//商品名称
            if (MapUtils.getInteger(params,"BiType")==1){
                payMap.put("commodityDesc", "房租");//商品描述
            }else if (MapUtils.getInteger(params,"BiType")==3){
                payMap.put("commodityDesc", "维修费用");//商品描述

            }else if (MapUtils.getInteger(params,"BiType")==4){
                payMap.put("commodityDesc", "临时账单");//商品描述

            }else if (MapUtils.getInteger(params,"BiType")==5){

                payMap.put("commodityDesc", "其他费用");//商品描述
            }else if (MapUtils.getInteger(params,"BiType")==6){

                payMap.put("commodityDesc", "退租账单");//商品描述
            }else if (MapUtils.getInteger(params,"BiType")==7){

                payMap.put("commodityDesc", "夜间开门");//商品描述
            }else if (MapUtils.getInteger(params,"BiType")==8){

                payMap.put("commodityDesc", "智能电表");//商品描述
            } else if (MapUtils.getInteger(params,"BiType")==9){

                payMap.put("commodityDesc", "续签剩余原合同总账单");//商品描述
            } else if (MapUtils.getInteger(params,"BiType")==10){

                payMap.put("commodityDesc", "延期退");//商品描述
            }else if (MapUtils.getInteger(params,"BiType")==11){

                payMap.put("commodityDesc", "业主违约退");//商品描述
            }
            payMap.put("orderDate", orderDate);//订单日期
            payMap.put("orderNo", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));//商户订单号

            JsonResult getAreaidResult = zuulFeignClient.getAreaid(params);
            Map<String, Object> getAreaid = (Map<String, Object>) getAreaidResult.get("result");

            if (MapUtils.getInteger(params,"prepayType")==1){//表示微信支付
                //获取openid
                Map<String, Object> tenOpIdMAP = wechatService.getTenOpenId(params);
                payMap.put("openid", tenOpIdMAP.get("uopid"));//微信用户id


                if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {

                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称


                } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {

                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称

                } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {

                    payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.KS_WXSMGRN);//微信子商户号
                    payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称

                }

                payMap.put("notifyUrl",NOTIFYURL);//回调地址

                Attestation = AlipayUtil.AliPayPublic(payMap);

            }else if(MapUtils.getInteger(params,"prepayType")==2){//表示支付宝支付


                if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {

                    //上海唐巢投资公司不用.合并到公租房

                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                    payMap.put("storeId", "tangchao001");//终端商户号名称
                    payMap.put("terminalId", "tangchao001");//终端商户号名称

                } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {

                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                    payMap.put("storeId", "tangchaoGZ001");//终端商户号名称
                    payMap.put("terminalId", "tangchaoGZ001");//终端商户号名称

                } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {

                    payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.KS_ZFSMGRN);//支付宝子商户号
                    payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
                    payMap.put("storeId", "kunshan001");//终端商户号名称
                    payMap.put("terminalId", "kunshan001");//终端商户号名称

                }

                payMap.put("notifyUrl", NOTIFYURL);//支付宝支付异步通知地址
                Attestation = AlipayUtil.ZhiFuBaopublic(payMap);
            }


            Map<String, Object> weChatMap = new HashMap<>();
            weChatMap.put("prepayId", payMap.get("orderNo"));
            weChatMap.put("prepayType",params.get("prepayType"));//1微信 2支付宝 3银联
            weChatMap.put("Source", params.get("BiId"));
            weChatMap.put("SouType", 1);
            weChatMap.put("Coucode", params.get("CouId"));
            weChatMap.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
            weChatMap.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(weChatMap);
            zpcGmioFeign.AddPayWechat(weChatMap);//保存本次订单号与账单编号之间的关系


        } else if (params.get("BiType").toString().equals("2") || (params.get("BiType").toString().equals("1") && params.get("DepositType").toString().equals("2"))) {//表示公共事业费或者水电押金,走银行卡转账


            //先走微信或者支付宝,后期走别的
            Map<String, Object> payMap = new HashMap<>();
            payMap.put("transAmt", (long) CompuUtils.mul(new Double(params.get("transAmt").toString()), new Double("100")));//交易金额(分)
            payMap.put("commodityName", params.get("BiName"));//商品名称
            payMap.put("commodityDesc", "公共事业费");//商品描述
            payMap.put("orderDate", orderDate);//订单日期
            payMap.put("orderNo", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));//商户订单号
            //   payMap.put("frontUrl", "http://www.4006269069.net/");//前台通知地址


            JsonResult getAreaidResult = zuulFeignClient.getAreaid(params);
            Map<String, Object> getAreaid = (Map<String, Object>) getAreaidResult.get("result");

            if (MapUtils.getInteger(params,"prepayType")==1){//表示微信支付
                //获取openid
                Map<String, Object> tenOpIdMAP = wechatService.getTenOpenId(params);
                payMap.put("openid", tenOpIdMAP.get("uopid"));//微信用户id


                payMap.put("merNo", Merchant.EWG_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.EWG_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.EWG_WXSMGRN);//微信子商户号
                payMap.put("subMerName", Merchant.EWG_TEMGRMING);//终端商户号名称


//                if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
//
//                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                    payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
//                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//
//
//                } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
//
//                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                    payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
//                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//
//                } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
//
//                    payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
//                    payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
//                    payMap.put("subChnlMerNo", Merchant.KS_WXSMGRN);//微信子商户号
//                    payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
//
//                }

                payMap.put("notifyUrl",NOTIFYURLYL);//回调地址

                Attestation = AlipayUtil.AliPayPublic(payMap);

            }else if(MapUtils.getInteger(params,"prepayType")==2){//表示支付宝支付


                payMap.put("merNo", Merchant.EWG_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.EWG_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.EWG_ZFSMGRN);//支付宝子商户号
                payMap.put("subMerName", Merchant.EWG_TEMGRMING);//终端商户号名称
                payMap.put("storeId", "tangchao001");//终端商户号名称
                payMap.put("terminalId", "tangchao001");//终端商户号名称


//                if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
//
//                    //上海唐巢投资公司不用.合并到公租房
//
//                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                    payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
//                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//                    payMap.put("storeId", "tangchao001");//终端商户号名称
//                    payMap.put("terminalId", "tangchao001");//终端商户号名称
//
//                } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
//
//                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
//                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
//                    payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
//                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
//                    payMap.put("storeId", "tangchaoGZ001");//终端商户号名称
//                    payMap.put("terminalId", "tangchaoGZ001");//终端商户号名称
//
//                } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
//
//                    payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
//                    payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
//                    payMap.put("subChnlMerNo", Merchant.KS_ZFSMGRN);//支付宝子商户号
//                    payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
//                    payMap.put("storeId", "kunshan001");//终端商户号名称
//                    payMap.put("terminalId", "kunshan001");//终端商户号名称
//
//                }

                payMap.put("notifyUrl", NOTIFYURLYL);//支付宝支付异步通知地址
                Attestation = AlipayUtil.ZhiFuBaopublic(payMap);
            }


//
//            payMap.put("notifyUrl",NOTIFYURLYL);//子商户号名称
//            Attestation = AlipayUtil.AliPayPrivate(payMap);


            Map<String, Object> weChatMap = new HashMap<>();
            weChatMap.put("prepayId", payMap.get("orderNo"));
            weChatMap.put("prepayType",params.get("prepayType"));//本次支付方式1微信2支付宝 3银联支付
            weChatMap.put("Source", params.get("BiId"));
            weChatMap.put("SouType", 2);
            weChatMap.put("Coucode", params.get("CouId"));
            weChatMap.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
            weChatMap.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(weChatMap);

            zpcGmioFeign.AddPayWechat(weChatMap);//保存本次订单号与账单编号之间的关系
        }

        return result.put(Attestation);
    }




    /**
     * 续租的时候支付未支付的房租账单
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/reletPaIdPay")
    public JsonResult reletPaIdPay(@RequestBody Map<String, Object> params) {
        //参数
        // BiIdList 房租账单集合
        // TenId,租客id
        // HouId,房源id
        // transAmt,支付金额
        //commodityName,商品名称
        //commodityDesc,商品描述
        //CouId//优惠券编号
        //PaId
        //支付类型 prepayType(1微信 2支付宝)
        //PaIdBillType(1表示房租 2表示公共事业费)
        JsonResult result = new JsonResult();
        String Attestation ="";//返回给前端的


        //获取当前时间
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String orderDate = sdf.format(nowTime);//租赁顾问签约抄水电燃,抄表记录的时间默认一致,

        Map<String, Object> payMap = new HashMap<>();
        payMap.put("transAmt", (long) CompuUtils.mul(MapUtils.getDouble(params, "transAmt"), new Double("100")));//交易金额(分)
        payMap.put("commodityName", params.get("commodityName"));//商品名称
        payMap.put("commodityDesc", params.get("commodityDesc"));//商品描述
        payMap.put("orderDate", orderDate);//商品描述
        payMap.put("orderNo", new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));//商户订单号

        //获取组可签约房子的房源编号
        JsonResult getHouCorIdResult = zpcMktFeign.getHouCorId(params);
        Map<String, Object> getHouCorId = (Map<String, Object>) getHouCorIdResult.get("result");
        getHouCorId.put("area_id", getHouCorId.get("CorId"));

        JsonResult getAreaidResult = zuulFeignClient.getAreaid(getHouCorId);
        Map<String, Object> getAreaid = (Map<String, Object>) getAreaidResult.get("result");

        if(MapUtils.getInteger(params,"PaIdBillType")==1){//表示房租
            if(MapUtils.getInteger(params,"prepayType")==1) {//表示微信支付
                //获取openid
                Map<String, Object> tenOpIdMAP = wechatService.getTenOpenId(params);
                payMap.put("openid", tenOpIdMAP.get("uopid"));//微信用户id
                if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
                    //上海唐巢投资公司不用.合并到公租房
                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_WXSMGRN);//微信子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
                    payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.KS_WXSMGRN);//微信子商户号
                    payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
                }
                payMap.put("notifyUrl", NOTIFYURLXZ);//微信支付异步通知地址
                Attestation = AlipayUtil.AliPayPublic(payMap);
            }else if(MapUtils.getInteger(params,"prepayType")==2){//支付宝支付
                if (getAreaid.get("name").toString().equals("上海唐巢投资有限公司")) {
                    //上海唐巢投资公司不用.合并到公租房
                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                    payMap.put("storeId", "tangchao001");//终端商户号名称
                    payMap.put("terminalId", "tangchao001");//终端商户号名称
                } else if (getAreaid.get("name").toString().equals("上海唐巢公共租赁住房运营有限公司")) {
                    payMap.put("merNo", Merchant.GZF_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.GZF_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.GZF_ZFSMGRN);//支付宝子商户号
                    payMap.put("subMerName", Merchant.GZF_TEMGRMING);//终端商户号名称
                    payMap.put("storeId", "tangchaoGZ001");//终端商户号名称
                    payMap.put("terminalId", "tangchaoGZ001");//终端商户号名称
                } else if (getAreaid.get("name").toString().equals("昆山唐巢公寓管理有限公司")) {
                    payMap.put("merNo", Merchant.KS_ORMERN);//机构商户号
                    payMap.put("terMerNo", Merchant.KS_TEMERN);//终端商户号
                    payMap.put("subChnlMerNo", Merchant.KS_ZFSMGRN);//支付宝子商户号
                    payMap.put("subMerName", Merchant.KS_TEMGRMING);//子商户号名称
                    payMap.put("storeId", "kunshan001");//终端商户号名称
                    payMap.put("terminalId", "kunshan001");//终端商户号名称
                }
                payMap.put("notifyUrl", NOTIFYURLXZ);//微信支付异步通知地址
                Attestation = AlipayUtil.ZhiFuBaopublic(payMap);
            }


        }else if(MapUtils.getInteger(params,"PaIdBillType")==2){//表示公共事业费

            if (MapUtils.getInteger(params,"prepayType")==1){//表示微信支付
                //获取openid
                Map<String, Object> tenOpIdMAP = wechatService.getTenOpenId(params);
                payMap.put("openid", tenOpIdMAP.get("uopid"));//微信用户id
                payMap.put("merNo", Merchant.EWG_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.EWG_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.EWG_WXSMGRN);//微信子商户号
                payMap.put("subMerName", Merchant.EWG_TEMGRMING);//终端商户号名称
                payMap.put("notifyUrl",NOTIFYURLXZ);//回调地址
                Attestation = AlipayUtil.AliPayPublic(payMap);

            }else if(MapUtils.getInteger(params,"prepayType")==2){//表示支付宝支付


                payMap.put("merNo", Merchant.EWG_ORMERN);//机构商户号
                payMap.put("terMerNo", Merchant.EWG_TEMERN);//终端商户号
                payMap.put("subChnlMerNo", Merchant.EWG_ZFSMGRN);//支付宝子商户号
                payMap.put("subMerName", Merchant.EWG_TEMGRMING);//终端商户号名称
                payMap.put("storeId", "tangchao001");//终端商户号名称
                payMap.put("terminalId", "tangchao001");//终端商户号名称
                payMap.put("notifyUrl", NOTIFYURLXZ);//支付宝支付异步通知地址
                Attestation = AlipayUtil.ZhiFuBaopublic(payMap);
            }

        }


        List<String> BiIdList = (List<String>) params.get("BiIdList");//未支付房租账单集合
        for (String BiIdss:BiIdList){
            Map<String, Object> weChatMap = new HashMap<>();
            weChatMap.put("prepayId", payMap.get("orderNo"));
            weChatMap.put("prepayType",params.get("prepayType"));//本次支付方式1微信2支付宝 3银联支付
            weChatMap.put("Source", BiIdss);//账单编号
            weChatMap.put("SourcePaId",params.get("PaId"));//关联合同编号
            weChatMap.put("SouType", params.get("PaIdBillType"));//1表示房租2表示公共事业费
            weChatMap.put("Coucode", params.get("CouId"));
            weChatMap.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
            weChatMap.put("fnc",
                    this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
            ParamsCommon.commonInsertParms(weChatMap);
            zpcGmioFeign.AddPayWechat(weChatMap);//保存本次订单号与账单编号之间的关系

        }

        return result.put(Attestation);

    }



    /**
     * 支付完成的回调
     *
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/reletPaIdPayCompleted")
    public String  reletPaIdPayCompleted(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        //获取当前时间
        Date nowTime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String GenerateTimeNow = sdf.format(nowTime);//租赁顾问签约抄水电燃,抄表记录的时间默认一致,
        if (params.get("respCode").toString().equals("0000")) {//是支付成功的操作


            Integer SouTypes = new Integer("0");
            String PaIds = "";
            String TenIds = "";
            //修改账单状态,增加支付信息。orderNo//订单编号
            params.put("prepayId", params.get("orderNo"));//本次支付订单号
            System.out.println("进入方法");
            System.out.println("进入方法的参数"+params);
            JsonResult getBillPayResult = zpcGmioFeign.getBillPay(params);
            List<Map<String, Object>> getBillPayMapList = (List<Map<String, Object>>) getBillPayResult.get("result");//根据订单信息查询关联账单
            for (Map<String, Object> getBillPayMap : getBillPayMapList) {
                SouTypes = MapUtils.getInteger(getBillPayMap,"SouType");
                PaIds = MapUtils.getString(getBillPayMap,"SourcePaId");
                Map<String, Object> map1 = new HashMap<>();
                map1.put("BiId", getBillPayMap.get("Source"));//账单编号
                JsonResult getFirsMonRentResult = zpcGmioFeign.getFirstRoomGEW(map1);//根据账单编号获取账单信息
                Map<String, Object> getFirstRoomGEWMap = (Map<String, Object>) getFirsMonRentResult.get("result");

                TenIds = MapUtils.getString(getFirstRoomGEWMap,"TenId");//获取租客编号


                //增加本次支付信息
                String PayIdUUID = "";//支付订单号
                //获取账单编号
                Map<String, Object> payIduuid = utilsMapper.getUUID(new HashMap<String, Object>() {{
                    put("uuid", "PayId");
                    put("database", Constants.DATA_SOURCE_GMIO);
                    put("surface", "tcgmio_bill_pay");
                }});
                if (payIduuid != null) {
                    int number = Integer.valueOf(payIduuid.get("uuid").toString());
                    PayIdUUID = ComUtils.getLocalTrmSeqNum("ZF", number);

                } else {
                    PayIdUUID = ComUtils.getLocalTrmSeqNum("ZF", 0);
                }

                Map<String, Object> AddPayWechat = new HashMap<String, Object>();
                AddPayWechat.put("term", "1");// 创建端 Insert端： 1 租客端 2市场部 3 工程部   4运营部   5财务部  6总经办 7发展部
                AddPayWechat.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonInsertParms(AddPayWechat);

                AddPayWechat.put("PayId", PayIdUUID);//支付信息编号
                AddPayWechat.put("TenId", getFirstRoomGEWMap.get("TenId"));//用户编号
                AddPayWechat.put("Shape", "0");//支付形式   0.线上   1.线下
                AddPayWechat.put("PayMode", getBillPayMap.get("prepayType"));//支付方式  1.微信  2.支付宝  3 银联支付
                AddPayWechat.put("TransactionId", params.get("orderNo"));//微信支付订单号	该字段只有线上微信支付才有
                AddPayWechat.put("PayTime", GenerateTimeNow);//支付时间
                AddPayWechat.put("BiMoney", getFirstRoomGEWMap.get("BiMoney"));//本次账单金额
                AddPayWechat.put("PatStats", "2");//支付状态    1.未支付  2.支付成功
                AddPayWechat.put("PayMoney", getFirstRoomGEWMap.get("BiMoney"));//支付金额
                if (FieldCheckUtil.isMapFieldNotNull(getBillPayMap, new String[]{"Coucode"})) {
                    Map<String, Object> getTenantCouCount = tctenTenantCouponsMapper.getTenantCouCount(new HashMap<String, Object>() {{
                        put("CouId", getBillPayMap.get("Coucode"));
                        put("TenId", getFirstRoomGEWMap.get("TenId"));
                    }});

                    //优惠券大于0
                    if (MapUtils.isNotEmpty(getTenantCouCount)) {
                        Map<String, Object> cou = new HashMap<String, Object>();
                        cou.put("CouId", getBillPayMap.get("Coucode"));
                        cou.put("TenId", getFirstRoomGEWMap.get("TenId"));
                        //修改优惠券已使用
                        tenantCouService.UpdateTenantCou(cou);
                        AddPayWechat.put("Couponcd", getBillPayMap.get("Coucode"));//优惠券编号
                        AddPayWechat.put("Couponamt", getTenantCouCount.get("Facevalue"));//优惠券金额
                        AddPayWechat.put("PayMoney", CompuUtils.reduce(MapUtils.getDouble(getFirstRoomGEWMap, "BiMoney"), MapUtils.getDouble(getTenantCouCount, "Facevalue")));//优惠券金额

                    }

                }

                //修改当前账单为支付成功
                Map<String, Object> map2 = new HashMap<>();
                map2.put("term","1");//1 租客端 2市场部 3 工程部 4运营部 5财务部 6总经办 7发展部
                map2.put("fnc",
                        this.getClass().getSimpleName() + "." + Thread.currentThread().getStackTrace()[1].getMethodName());// 创建Function名
                ParamsCommon.commonUpdateParms(map2);
                map2.put("PayId", PayIdUUID);//支付信息编号
                map2.put("Status", 2);//账单状态   1.待支付  2.支付完成
                map2.put("Abnormal", 0);//账单异常状态   0正常   1异常
                map2.put("BiId", getFirstRoomGEWMap.get("BiId"));

                if (MapUtils.getInteger(getFirstRoomGEWMap,"Status")!=2) {
                    zpcGmioFeign.UpdateBill(map2);
                }
                if (MapUtils.getString(getFirstRoomGEWMap,"PayId")==null||MapUtils.getString(getFirstRoomGEWMap,"PayId").equals("")){
                    zpcGmioFeign.AddBillPay(AddPayWechat);//增加支付信息
                }else{
                    JsonResult PayResult =  zpcGmioFeign.getBillPays(getFirstRoomGEWMap);
                    Map<String,Object> PayMap = (Map<String, Object>) PayResult.get("result");
                    if (MapUtils.getInteger(PayMap,"coutPay")==0){
                        zpcGmioFeign.AddBillPay(AddPayWechat);//增加支付信息
                    }
                }
            }


            //如果该房源是智能门锁,那么就要修改门锁的时间为合同到期,并且是支付房租的操作
            if (SouTypes==1){//本次是房租支付的操作

                //修改门锁的时间
                //获取合同的结束时间



                params.put("TenId",TenIds);
                //获取在租租客的手机号
                Map<String,Object> PhoneMap = tenantCouService.getTenPhone(params);//获取在租租客的手机号
                params.put("phone",PhoneMap.get("TenPhone"));//获取租客手机号
                params.put("PaId",PaIds);
                List<Map<String,Object>> identifierList = new ArrayList<>();
                //根据合同编号,去合同表查询智能门锁的情况
                JsonResult resultRoom = zpcMktFeign.getIntelligentRoom(params);
                Map<String,Object> IntellMap = (Map<String,Object>)resultRoom.get("result");
                Integer IntelligentOpenType= new Integer("0");
                if (IntellMap !=null){
                    IntelligentOpenType = MapUtils.getInteger(IntellMap,"IntelligentOpenType");
                    params.put("EndTime",IntellMap.get("IntellMap").toString());//合同结束时间
                    if (MapUtils.getString(IntellMap,"IntelligentRoom")!=null&&!MapUtils.getString(IntellMap,"IntelligentRoom").equals("")){
                        String IntelligentRoom = MapUtils.getString(IntellMap,"IntelligentRoom");
                        String IntelligentRooms = IntelligentRoom.substring(0,IntelligentRoom.length()-1);
                        String[] arr1 = IntelligentRooms.split(",");
                        for(String arrStr:arr1){
                            Map<String,Object> identMap = new HashMap<>();
                            identMap.put("Intelligent",IntellMap.get("IntelligentType"));//锁类型
                            identMap.put("Identifier",arrStr.substring(0,arrStr.indexOf(":")));//锁编号
                            identMap.put("CodeId",arrStr.substring(arrStr.indexOf(":")+1));//钥匙
                            identifierList.add(identMap);
                        }
                    }
                }
                if(identifierList.size()>0){//有智能设备

                    //修改智能门锁周期
                    for (Map<String,Object> InteMap:identifierList){
                        //Intelligent 0.蜂电   1.大华   2.科技侠   3.果加
                        if (InteMap.get("Intelligent").toString().equals("2")){
                            String DeviceLockToken=redisUtils.get("DeviceLockToken");
                            //如果获取不到就重新登录
                            if (DeviceLockToken==null){
                                Map<String,Object> tokenMap=new HashMap<String, Object>();
                                params.put("client_id", InteDeviceLockConfig.CLIENT_ID);
                                params.put("client_secret",InteDeviceLockConfig.CLIENT_SECRET);
                                params.put("grant_type",InteDeviceLockConfig.GRANT_TYPE_PASSWORD);
                                params.put("username",InteDeviceLockConfig.USERNAME);
                                params.put("password",InteDeviceLockConfig.PASSWORD);
                                params.put("redirect_uri",InteDeviceLockConfig.REDIRECT_URL);
                                tokenMap= InteDeviceLockUtil.oauth2Token(params);
                                if (tokenMap.get("access_token")!=null){
                                    DeviceLockToken=tokenMap.get("access_token").toString();
                                    //token存到redis中
                                    redisUtils.set("DeviceLockToken",DeviceLockToken,Long.valueOf(tokenMap.get("expires_in").toString()));
                                }else{
                                    result.putFailed("token获取失败");
                                }
                            }

                            Map<String,Object> sendMap = new HashMap<>();
                            sendMap.put("clientId", InteDeviceLockConfig.CLIENT_ID);//应用编号
                            sendMap.put("accessToken",DeviceLockToken);//访问令牌
                           // sendMap.put("keyId",InteMap.get("CodeId"));//智能设备编号
                            sendMap.put("startDate",InteDeviceLockUtil.getTimeSign());//当前时间
                            //  sendMap.put("startDate",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("StartTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_START,"yyyy-MM-dd HH:mm:ss"));
                            sendMap.put("endDate",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                            sendMap.put("date",InteDeviceLockUtil.getTimeSign());//当前时间(毫秒数)

                            if (IntelligentOpenType==0){
                                sendMap.put("keyId",InteMap.get("CodeId"));//智能设备编号

                                Map<String,Object> mapResult=InteDeviceLockUtil.keyChangePeriod(sendMap);//修改科技侠有效期
                                System.out.println("钥匙返回的参数:"+mapResult);
                                System.out.println("InteMap1:"+InteMap);
                                if (mapResult.get("errcode")!=null && mapResult.get("errcode").toString().equals("0")){
                                    result.putSuccess("修改科技侠智能门锁成功");

                                }else{
                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                    result.putFailed(mapResult.get("errmsg").toString());
                                }

                            }else if (IntelligentOpenType==1){

                                sendMap.put("keyboardPwdId",InteMap.get("CodeId"));//智能设备编号
                                sendMap.put("lockId",InteMap.get("Identifier"));//智能设备编号
                                Map<String,Object> mapResult=InteDeviceLockUtil.keyboardPwdChange(sendMap);//修改科技侠有效期
                                System.out.println("钥匙返回的参数:"+mapResult);
                                System.out.println("InteMap1:"+InteMap);
                                if (mapResult.get("errcode")!=null && mapResult.get("errcode").toString().equals("0")){
                                    result.putSuccess("修改科技侠智能门锁成功");

                                }else{
                                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                    result.putFailed(mapResult.get("errmsg").toString());
                                }



                            }





                        }else if(InteMap.get("Intelligent").toString().equals("3")){//果加
                            String GuoJiaToken=redisUtils.get("GuoJiaToken");
                            //如果获取不到就重新登录
                            if (GuoJiaToken==null){
                                Map<String,Object> guoJiaMap=new HashMap<String, Object>();
                                guoJiaMap.put("s_id", InteGuoJiaUtil.getSid());
                                guoJiaMap.put("version","1");
                                com.alibaba.fastjson.JSONObject bodyJson=new com.alibaba.fastjson.JSONObject();
                                //key
                                DESEncrypt desPlus2 = new DESEncrypt(InteGuoJiaConfig.DES_KEY);
                                //密码
                                bodyJson.put("account",InteGuoJiaConfig.ACCOUNT);
                                bodyJson.put("password",desPlus2.encrypt(InteGuoJiaConfig.PASSWORD));
                                guoJiaMap= InteGuoJiaUtil.login(guoJiaMap,bodyJson);
                                //返回的token数据
                                Map<String,Object>dataMap=(Map<String,Object>)guoJiaMap.get("data");
                                if (guoJiaMap.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                    GuoJiaToken=dataMap.get("access_token").toString();
                                    //token存到redis中
                                    redisUtils.set("GuoJiaToken",GuoJiaToken,Long.valueOf(dataMap.get("expires_second").toString()));
                                }else{
                                    result.putFailed("token获取失败");
                                }
                            }
                            //先解除果加的门锁授权在重新授权
                            Map<String,Object> headParams=new HashMap<String, Object>();
                            headParams.put("s_id",InteGuoJiaUtil.getSid());
                            headParams.put("version","1");
                            headParams.put("access_token",GuoJiaToken);



                            if (IntelligentOpenType==0){


                                JSONObject bodyJsonOne=new JSONObject();
                                bodyJsonOne.put("lock_no",InteMap.get("Identifier"));//门锁编码
                                bodyJsonOne.put("mobile",params.get("phone"));
                                Map<String,Object> JieChuMap = InteGuoJiaUtil.lockCancel_auth(headParams,bodyJsonOne);
                                if (JieChuMap.get("rlt_code") !=null && JieChuMap.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                    //解除成功再去授权
                                    JSONObject bodyJson=new JSONObject();
                                    bodyJson.put("operate_pwd_auth","N");//是否允许操作密码 Y 允许 N 不允许
                                    bodyJson.put("set_custom_pwd","N");//是否允许设置自定义密码 Y 允许 N 不允许智能是否允许设置自定义密码 Y 允许 N 不允许
                                    bodyJson.put("lock_no",InteMap.get("Identifier"));//智能门锁的设备编号
                                    bodyJson.put("mobile",params.get("phone"));//用户手机号
                                    bodyJson.put("auth_time_start",InteDeviceLockUtil.getTimeSign());
                                    // bodyJson.put("auth_time_start",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("StartTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_START,"yyyy-MM-dd HH:mm:ss"));
                                    bodyJson.put("auth_time_end",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                                    Map<String,Object> guoJiaResult=InteGuoJiaUtil.lockAuth(headParams,bodyJson);
                                    if (guoJiaResult.get("rlt_code") !=null && guoJiaResult.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                        InteMap.put("CodeId",InteMap.get("Identifier"));//钥匙的编码就存智能设备编码
                                        //InteMap.put("Code",InteMap.get("TenMode"));//果加的密码就存租客手机号
                                    }else{
                                        result.putFailed(guoJiaResult.get("rlt_msg").toString());
                                    }

                                }else{
                                    result.putFailed(JieChuMap.get("rlt_msg").toString());
                                }

                            }else if (IntelligentOpenType==1){

                                JSONObject bodyJsonOne=new JSONObject();
                                bodyJsonOne.put("lock_no",InteMap.get("Identifier"));//门锁编码
                                bodyJsonOne.put("pwd_no",InteMap.get("CodeId"));//密码id
                                bodyJsonOne.put("valid_time_start",InteDeviceLockUtil.getTimeSign());
                                bodyJsonOne.put("valid_time_end",InteDeviceLockUtil.getTimeSign(DateUtils.format(DateUtils.addDateMonths( DateUtils.stringToDate(params.get("EndTime").toString(),"yyyy-MM-dd"),0))+InteDeviceLockConfig.LOCK_TIME_END,"yyyy-MM-dd HH:mm:ss"));
                                Map<String,Object> guoJiaResult=InteGuoJiaUtil.pwd_update(headParams,bodyJsonOne);
                                if (guoJiaResult.get("rlt_code") !=null && guoJiaResult.get("rlt_code").toString().equals("HH0000")){//HH0000 、成功
                                    InteMap.put("CodeId",InteMap.get("Identifier"));//钥匙的编码就存智能设备编码
                                    //InteMap.put("Code",InteMap.get("TenMode"));//果加的密码就存租客手机号
                                }else{
                                    result.putFailed(guoJiaResult.get("rlt_msg").toString());
                                }

                            }



                        }
                    }

                }

            }

        }
        return "SUCCESS";
    }

}